/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: HP
 * Date: 2023 -04 -06
 * Time: 16:39
 */

class Animal implements Cloneable {
    private String name;
    @Override
    public Animal clone() {
        Animal o = null;
        try {
            o = (Animal)super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return o;
    }
}

class Money implements Cloneable {
    public double m = 99.99;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public Money money = new Money();
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person p=(Person)super.clone();
        p.money=(Money)money.clone();
        return p;
    }
}
class Test3 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2 = (Person) person1.clone();
        System.out.println("通过person2修改前的结果");
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
        person2.money.m = 13.6;
        System.out.println("通过person2修改后的结果");
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
    }
}










public class Test2 {
    public static void main(String[] args) {
        Animal animal1 = new Animal();
        Animal animal12 = animal1;//引用同一个对象
        System.out.println(animal1 == animal12);
        Animal animal = new Animal();
        Animal animal2 = animal.clone();//进行拷贝
        System.out.println(animal == animal2);//对象的地址不同
    }
}
